﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using SoucreGame.GLO;

namespace SoucreGame.GUI
{
    class guiLevel
    {
        // Cac thanh phan giao dien ve tren man choi
        Texture2D anhNen;  // hinh anh lam nen
        Texture2D cmdCaiDat;
        Texture2D cmdChoiTiep;
        Texture2D cmdMoi;
        Texture2D cmdThoatLevel;
        Texture2D guiKhung;
        Texture2D cmdLV1;
        Texture2D cmdLV2;
        Texture2D cmdLV3;
        Texture2D cmdLV4;
        Texture2D cmdLV5;
        Texture2D cmdLV6;
        Texture2D cmdLV7;
        Texture2D cmdLV8;
        Texture2D cmdLV9;
        Texture2D cmdLV10;
        Texture2D cmdLV11;
        Texture2D cmdLV12;
        Texture2D cmdLV13;
        Texture2D cmdLV14;
        Texture2D cmdLV15;
        Texture2D cmdLV16;
        Texture2D cmdLV17;
        Texture2D cmdLV18;


        Dictionary<string, Rectangle> dsToaDoGiaoDien; // DUNG DE DOC FILE XML
        ContentManager content; // BIEN DE LOAD DU LIEU
        GameTime gameTime;
        SpriteBatch spriteBatch;
 
        public guiLevel( ContentManager _content, GameTime _gameTime, SpriteBatch _spritBatch)
        {
            content = _content; // DONG NHAT(KHOI TAO)
            gameTime = _gameTime;
            spriteBatch = _spritBatch;

            if (content != null)
            {
                anhNen = content.Load<Texture2D>("GUII\\guiLevel");
                cmdCaiDat = content.Load<Texture2D>("GUII\\cmdCaiDat");
                cmdChoiTiep = content.Load<Texture2D>("GUII\\cmdChoiTiep");
                cmdMoi = content.Load<Texture2D>("GUII\\cmdMoi");
                cmdThoatLevel = content.Load<Texture2D>("GUII\\cmdThoatLevel");
                guiKhung = content.Load<Texture2D>("GUII\\guiKhung");
                cmdLV1 = content.Load<Texture2D>("GUII\\cmdLV1");
                cmdLV2 = content.Load<Texture2D>("GUII\\cmdLV2");
                cmdLV3 = content.Load<Texture2D>("GUII\\cmdLV3");
                cmdLV4 = content.Load<Texture2D>("GUII\\cmdLV4");
                cmdLV5 = content.Load<Texture2D>("GUII\\cmdLV5");
                cmdLV6 = content.Load<Texture2D>("GUII\\cmdLV6");
                cmdLV7 = content.Load<Texture2D>("GUII\\cmdLV7");
                cmdLV8 = content.Load<Texture2D>("GUII\\cmdLV8");
                cmdLV9 = content.Load<Texture2D>("GUII\\cmdLV9");
                cmdLV10 = content.Load<Texture2D>("GUII\\cmdLV10");
                cmdLV11 = content.Load<Texture2D>("GUII\\cmdLV11");
                cmdLV12 = content.Load<Texture2D>("GUII\\cmdLV12");
                cmdLV13 = content.Load<Texture2D>("GUII\\cmdLV13");
                cmdLV14 = content.Load<Texture2D>("GUII\\cmdLV14");
                cmdLV15 = content.Load<Texture2D>("GUII\\cmdLV15");
                cmdLV16 = content.Load<Texture2D>("GUII\\cmdLV16");
                cmdLV17 = content.Load<Texture2D>("GUII\\cmdLV17");
                cmdLV18 = content.Load<Texture2D>("GUII\\cmdLV18");



               dsToaDoGiaoDien = content.Load<Dictionary<string, Rectangle>>("GUII\\guiViTri");
            }
        }

        public void Update(GameTime gameTime)
        {
            CGlobalvariable.trangthaitruoc = CGlobalvariable.trangthaihientai;
            CGlobalvariable.trangthaihientai = Mouse.GetState();
            if (CGlobalvariable.trangthaihientai.LeftButton == ButtonState.Pressed && CGlobalvariable.trangthaitruoc.LeftButton == ButtonState.Released)
            {
                if (dsToaDoGiaoDien["cmdMoi"].Contains(new Point(CGlobalvariable.trangthaihientai.X, CGlobalvariable.trangthaihientai.Y)))
                {
                    CGlobalvariable.Chuyengiaodien = true;
                    CGlobalvariable.Giaodiendangchon = GUIEnum.guiDatTen;
                }
                else if (dsToaDoGiaoDien["cmdChoiTiep"].Contains(new Point(CGlobalvariable.trangthaihientai.X, CGlobalvariable.trangthaihientai.Y)))
                {
                    CGlobalvariable.Chuyengiaodien = true;
                    CGlobalvariable.Giaodiendangchon = GUIEnum.guiMapGamePlay;
                }

                else if (dsToaDoGiaoDien["cmdCaiDat"].Contains(new Point(CGlobalvariable.trangthaihientai.X, CGlobalvariable.trangthaihientai.Y)))
                {
                    CGlobalvariable.Chuyengiaodien = true;
                    CGlobalvariable.Giaodiendangchon = GUIEnum.guiCaiDat;
                }

                else if (dsToaDoGiaoDien["cmdThoatLevel"].Contains(new Point(CGlobalvariable.trangthaihientai.X, CGlobalvariable.trangthaihientai.Y)))
                {
                    CGlobalvariable.Chuyengiaodien = true;
                    CGlobalvariable.Giaodiendangchon = GUIEnum.guiManHinhThoat;
                }

                else if (dsToaDoGiaoDien["cmdLV1"].Contains(new Point(CGlobalvariable.trangthaihientai.X, CGlobalvariable.trangthaihientai.Y)))
                {
                    CGlobalvariable.Chuyengiaodien = true;
                    CGlobalvariable.Giaodiendangchon = GUIEnum.guiMapGamePlay;
                }

                else if (dsToaDoGiaoDien["cmdLV2"].Contains(new Point(CGlobalvariable.trangthaihientai.X, CGlobalvariable.trangthaihientai.Y)))
                {
                    CGlobalvariable.Chuyengiaodien = true;
                    CGlobalvariable.Giaodiendangchon = GUIEnum.guiMapGamePlay;
                }

                else if (dsToaDoGiaoDien["cmdLV3"].Contains(new Point(CGlobalvariable.trangthaihientai.X, CGlobalvariable.trangthaihientai.Y)))
                {
                    CGlobalvariable.Chuyengiaodien = true;
                    CGlobalvariable.Giaodiendangchon = GUIEnum.guiMapGamePlay;
                }

                else if (dsToaDoGiaoDien["cmdLV4"].Contains(new Point(CGlobalvariable.trangthaihientai.X, CGlobalvariable.trangthaihientai.Y)))
                {
                    CGlobalvariable.Chuyengiaodien = true;
                    CGlobalvariable.Giaodiendangchon = GUIEnum.guiMapGamePlay;
                }

                else if (dsToaDoGiaoDien["cmdLV5"].Contains(new Point(CGlobalvariable.trangthaihientai.X, CGlobalvariable.trangthaihientai.Y)))
                {
                    CGlobalvariable.Chuyengiaodien = true;
                    CGlobalvariable.Giaodiendangchon = GUIEnum.guiMapGamePlay;
                }

                else if (dsToaDoGiaoDien["cmdLV6"].Contains(new Point(CGlobalvariable.trangthaihientai.X, CGlobalvariable.trangthaihientai.Y)))
                {
                    CGlobalvariable.Chuyengiaodien = true;
                    CGlobalvariable.Giaodiendangchon = GUIEnum.guiMapGamePlay;
                }

                else if (dsToaDoGiaoDien["cmdLV7"].Contains(new Point(CGlobalvariable.trangthaihientai.X, CGlobalvariable.trangthaihientai.Y)))
                {
                    CGlobalvariable.Chuyengiaodien = true;
                    CGlobalvariable.Giaodiendangchon = GUIEnum.guiMapGamePlay;
                }

                else if (dsToaDoGiaoDien["cmdLV8"].Contains(new Point(CGlobalvariable.trangthaihientai.X, CGlobalvariable.trangthaihientai.Y)))
                {
                    CGlobalvariable.Chuyengiaodien = true;
                    CGlobalvariable.Giaodiendangchon = GUIEnum.guiMapGamePlay;
                }

                else if (dsToaDoGiaoDien["cmdLV9"].Contains(new Point(CGlobalvariable.trangthaihientai.X, CGlobalvariable.trangthaihientai.Y)))
                {
                    CGlobalvariable.Chuyengiaodien = true;
                    CGlobalvariable.Giaodiendangchon = GUIEnum.guiMapGamePlay;
                }

                else if (dsToaDoGiaoDien["cmdLV10"].Contains(new Point(CGlobalvariable.trangthaihientai.X, CGlobalvariable.trangthaihientai.Y)))
                {
                    CGlobalvariable.Chuyengiaodien = true;
                    CGlobalvariable.Giaodiendangchon = GUIEnum.guiMapGamePlay;
                }

                else if (dsToaDoGiaoDien["cmdLV11"].Contains(new Point(CGlobalvariable.trangthaihientai.X, CGlobalvariable.trangthaihientai.Y)))
                {
                    CGlobalvariable.Chuyengiaodien = true;
                    CGlobalvariable.Giaodiendangchon = GUIEnum.guiMapGamePlay;
                }

                else if (dsToaDoGiaoDien["cmdLV12"].Contains(new Point(CGlobalvariable.trangthaihientai.X, CGlobalvariable.trangthaihientai.Y)))
                {
                    CGlobalvariable.Chuyengiaodien = true;
                    CGlobalvariable.Giaodiendangchon = GUIEnum.guiMapGamePlay;
                }

                else if (dsToaDoGiaoDien["cmdLV13"].Contains(new Point(CGlobalvariable.trangthaihientai.X, CGlobalvariable.trangthaihientai.Y)))
                {
                    CGlobalvariable.Chuyengiaodien = true;
                    CGlobalvariable.Giaodiendangchon = GUIEnum.guiMapGamePlay;
                }

                else if (dsToaDoGiaoDien["cmdLV14"].Contains(new Point(CGlobalvariable.trangthaihientai.X, CGlobalvariable.trangthaihientai.Y)))
                {
                    CGlobalvariable.Chuyengiaodien = true;
                    CGlobalvariable.Giaodiendangchon = GUIEnum.guiMapGamePlay;
                }

                else if (dsToaDoGiaoDien["cmdLV15"].Contains(new Point(CGlobalvariable.trangthaihientai.X, CGlobalvariable.trangthaihientai.Y)))
                {
                    CGlobalvariable.Chuyengiaodien = true;
                    CGlobalvariable.Giaodiendangchon = GUIEnum.guiMapGamePlay;
                }

                else if (dsToaDoGiaoDien["cmdLV16"].Contains(new Point(CGlobalvariable.trangthaihientai.X, CGlobalvariable.trangthaihientai.Y)))
                {
                    CGlobalvariable.Chuyengiaodien = true;
                    CGlobalvariable.Giaodiendangchon = GUIEnum.guiMapGamePlay;
                }

                else if (dsToaDoGiaoDien["cmdLV17"].Contains(new Point(CGlobalvariable.trangthaihientai.X, CGlobalvariable.trangthaihientai.Y)))
                {
                    CGlobalvariable.Chuyengiaodien = true;
                    CGlobalvariable.Giaodiendangchon = GUIEnum.guiMapGamePlay;
                }

                else if (dsToaDoGiaoDien["cmdLV18"].Contains(new Point(CGlobalvariable.trangthaihientai.X, CGlobalvariable.trangthaihientai.Y)))
                {
                    CGlobalvariable.Chuyengiaodien = true;
                    CGlobalvariable.Giaodiendangchon = GUIEnum.guiMapGamePlay;
                }
            }
        }

        public void Draw(GameTime gameTime)
        {
            this.spriteBatch.Draw(anhNen, Vector2.Zero, Color.White);
            this.spriteBatch.Draw(guiKhung, new Vector2(dsToaDoGiaoDien["guiKhung"].X, dsToaDoGiaoDien["guiKhung"].Y), Color.White);
            this.spriteBatch.Draw(cmdMoi, new Vector2(dsToaDoGiaoDien["cmdMoi"].X, dsToaDoGiaoDien["cmdMoi"].Y), Color.White);
            this.spriteBatch.Draw(cmdCaiDat, new Vector2(dsToaDoGiaoDien["cmdCaiDat"].X, dsToaDoGiaoDien["cmdCaiDat"].Y), Color.White);
            this.spriteBatch.Draw(cmdChoiTiep, new Vector2(dsToaDoGiaoDien["cmdChoiTiep"].X, dsToaDoGiaoDien["cmdChoiTiep"].Y), Color.White);
            this.spriteBatch.Draw(cmdThoatLevel,new Vector2(dsToaDoGiaoDien["cmdThoatLevel"].X, dsToaDoGiaoDien["cmdThoatLevel"].Y), Color.White);
            this.spriteBatch.Draw(cmdLV1, new Vector2(dsToaDoGiaoDien["cmdLV1"].X, dsToaDoGiaoDien["cmdLV1"].Y), Color.White);
            this.spriteBatch.Draw(cmdLV2, new Vector2(dsToaDoGiaoDien["cmdLV2"].X, dsToaDoGiaoDien["cmdLV2"].Y), Color.White);
            this.spriteBatch.Draw(cmdLV3, new Vector2(dsToaDoGiaoDien["cmdLV3"].X, dsToaDoGiaoDien["cmdLV3"].Y), Color.White);
            this.spriteBatch.Draw(cmdLV4, new Vector2(dsToaDoGiaoDien["cmdLV4"].X, dsToaDoGiaoDien["cmdLV4"].Y), Color.White);
            this.spriteBatch.Draw(cmdLV5, new Vector2(dsToaDoGiaoDien["cmdLV5"].X, dsToaDoGiaoDien["cmdLV5"].Y), Color.White);
            this.spriteBatch.Draw(cmdLV6, new Vector2(dsToaDoGiaoDien["cmdLV6"].X, dsToaDoGiaoDien["cmdLV6"].Y), Color.White);
            this.spriteBatch.Draw(cmdLV7, new Vector2(dsToaDoGiaoDien["cmdLV7"].X, dsToaDoGiaoDien["cmdLV7"].Y), Color.White);
            this.spriteBatch.Draw(cmdLV8, new Vector2(dsToaDoGiaoDien["cmdLV8"].X, dsToaDoGiaoDien["cmdLV8"].Y), Color.White);
            this.spriteBatch.Draw(cmdLV9, new Vector2(dsToaDoGiaoDien["cmdLV9"].X, dsToaDoGiaoDien["cmdLV9"].Y), Color.White);
            this.spriteBatch.Draw(cmdLV10, new Vector2(dsToaDoGiaoDien["cmdLV10"].X, dsToaDoGiaoDien["cmdLV10"].Y), Color.White);
            this.spriteBatch.Draw(cmdLV11, new Vector2(dsToaDoGiaoDien["cmdLV11"].X, dsToaDoGiaoDien["cmdLV11"].Y), Color.White);
            this.spriteBatch.Draw(cmdLV12, new Vector2(dsToaDoGiaoDien["cmdLV12"].X, dsToaDoGiaoDien["cmdLV12"].Y), Color.White);
            this.spriteBatch.Draw(cmdLV13, new Vector2(dsToaDoGiaoDien["cmdLV13"].X, dsToaDoGiaoDien["cmdLV13"].Y), Color.White);
            this.spriteBatch.Draw(cmdLV14, new Vector2(dsToaDoGiaoDien["cmdLV14"].X, dsToaDoGiaoDien["cmdLV14"].Y), Color.White);
            this.spriteBatch.Draw(cmdLV15, new Vector2(dsToaDoGiaoDien["cmdLV15"].X, dsToaDoGiaoDien["cmdLV15"].Y), Color.White);
            this.spriteBatch.Draw(cmdLV16, new Vector2(dsToaDoGiaoDien["cmdLV16"].X, dsToaDoGiaoDien["cmdLV16"].Y), Color.White);
            this.spriteBatch.Draw(cmdLV17, new Vector2(dsToaDoGiaoDien["cmdLV17"].X, dsToaDoGiaoDien["cmdLV17"].Y), Color.White);
            this.spriteBatch.Draw(cmdLV18, new Vector2(dsToaDoGiaoDien["cmdLV18"].X, dsToaDoGiaoDien["cmdLV18"].Y), Color.White);
            
        }
    }
}
